package cn.itrip.service.impl;

import cn.itrip.entity.ItripProductStore;
import cn.itrip.dao.ItripProductStoreDao;
import cn.itrip.service.ItripProductStoreService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 原始库存表(ItripProductStore)表服务实现类
 *
 * @author makejava
 * @since 2022-04-14 22:34:59
 */
@Service("itripProductStoreService")
public class ItripProductStoreServiceImpl implements ItripProductStoreService {
	@Resource
	private ItripProductStoreDao itripProductStoreDao;

	/**
	 * 通过ID查询单条数据
	 *
	 * @param id 主键
	 * @return 实例对象
	 */
	@Override
	public ItripProductStore queryById(Long id) {
		return this.itripProductStoreDao.queryById(id);
	}

	/**
	 * 分页查询
	 *
	 * @param itripProductStore 筛选条件
	 * @param pageRequest       分页对象
	 * @return 查询结果
	 */
	@Override
	public Page<ItripProductStore> queryByPage(ItripProductStore itripProductStore, PageRequest pageRequest) {
		long total = this.itripProductStoreDao.count(itripProductStore);
		return new PageImpl<>(this.itripProductStoreDao.queryAllByLimit(itripProductStore, pageRequest), pageRequest, total);
	}

	/**
	 * 新增数据
	 *
	 * @param itripProductStore 实例对象
	 * @return 实例对象
	 */
	@Override
	public ItripProductStore insert(ItripProductStore itripProductStore) {
		this.itripProductStoreDao.insert(itripProductStore);
		return itripProductStore;
	}

	/**
	 * 修改数据
	 *
	 * @param itripProductStore 实例对象
	 * @return 实例对象
	 */
	@Override
	public ItripProductStore update(ItripProductStore itripProductStore) {
		this.itripProductStoreDao.update(itripProductStore);
		return this.queryById(itripProductStore.getId());
	}

	/**
	 * 通过主键删除数据
	 *
	 * @param id 主键
	 * @return 是否成功
	 */
	@Override
	public boolean deleteById(Long id) {
		return this.itripProductStoreDao.deleteById(id) > 0;
	}
}
